<?php
/**
 * Announces List for a selected mission
 * 
 */

/* $mission Hive\Mission */
use Fox\Behaviors;
use Hive\Mission;
use Fox\Generator;
use Fox\Html\Button;
use Fox\Ddic\DataElement\Text;
use Fox\Html\Header\Content;

$xview = Xview::instance();
$mission = $xview->component('missions', 'object');
// Customizing
$customizing = Hive\Mission\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'missions','act'=>'announces'));

$announces = $mission->announces();
$title = new Content('announces',Msg(Hive::BUNDLE,Hive::TITLE_ANNOUNCES));
$title->add(new Button('add','?',Msg(Hive::BUNDLE,Hive::BUT_ADD_ANNOUNCE)))
		->color(Button::COLOR_WARNING)
		->behaviors(Behaviors::action(
				Generator::url(Mission::BUNDLE_NAME,'announces','add',array('missionid' => $mission->getId())),
				true,null,null,true));
?>
<div id="announcesContent">
	<div class="page-header">
	<?php  echo $title->render();?>
	</div>
	<div class="contentArea">
		<ul class="uiList ">
		<?php 
			if(count($announces) > 0)
			{
				$language = $xview->language();
				// Load Announce Status Label
				$statuses = Fox\Dao::finder(Hive\Mission\Announce\Status::className())->where('language = ?',array($language))
							->find();
				foreach($statuses as $status) {
					$statusLabel[$status->status] = $status->label;
				}
				foreach($announces as $announce)
				{
					$aid = $announce->announceid;
					$data = $announce->getData();
					// Update
					$behaviorUpdate = new Behaviors(Behaviors::action(Generator::url('missions','announces','update',
												array('mid' => $mission->getId(),'aid' => $announce->announceid)),true,null,null,true));
					$behaviorUpdate->add(Behaviors::value('slink'));
					// Delete
					$behaviorDelete = new Behaviors(Behaviors::action(Generator::url('missions','announces','delete',
												array('mid' => $mission->getId(),'aid' => $announce->announceid)),true,null,null,true));
					$behaviorDelete->add(Behaviors::value('slink del'));
				
					$statusText = Msg(Hive::BUNDLE,Hive::ANNOUNCE_STATUS,$statusLabel[$announce->status]);
					// Change Text
					$dateTime = new DateTime($announce->udate);
					$dateString = Fox\Utilities\Dates::dateTimeToFullString($announce->udate);
					$subTitle = Msg(Hive::BUNDLE,Hive::ANNOUNCE_LAST_UPDATE,User::fullName($announce->uname),$dateString,$dateTime->format('H:i'));
					$skillsHtml = $rightHtml = $leftHtml = null;
					// Job Caracteristics
					if(!empty($data['contract_type'])) {
						$contractType = \Fox\Dao::load(Hive\Job\Contract\Type::className(),$data['contract_type']);
						$contractTypeLabel = $contractType->label();
						$leftHtml .= '<p><i class="icon contract-type"></i>'.Text::label('contract_type').' : '.$contractTypeLabel.'</p>';
					}
					// Edudcation
					if(!empty($data['education_level'])) {
						$educationLevel = \Fox\Dao::load(Hive\Education\Level::className(),$data['education_level']);
						$educationLevelLabel = $educationLevel->label();
						$leftHtml .= '<p><i class="icon education-level"></i>'.Text::label('education_level').' : '.$educationLevelLabel.'</p>';
					}	
					// Salary
					if(!empty($data['salary'])) {
						$leftHtml .= '<p><i class="icon salary"></i>'.Text::label('announce_salary').' : '.$data['salary'].'</p>';
					}	
					// Starts On
					if(!empty($data['start_date'])) {
						$startDate = new DateTime($data['start_date']);
						$leftHtml .= '<p><i class="icon start-date"></i>'.Text::label('announce_start_date').' : '.$startDate->format(User::current()->dateFormat()).'</p>';
					}
					// Time Slot
					if(!empty($data['timeslot'])) {
						/*
						$timeslot = \Fox\Dao::load(Hive\Job\Contract\TimeSlot::className(),$data['timeslot'].':'.$language);
						$timeslotLabel = $timeslot->label;
						*/
						$timeslotLabel = $data['timeslot'];
						$rightHtml .= '<p><i class="icon timeslot"></i>'.Text::label('contract_time_slot').' : '.$timeslotLabel.'</p>';
					}		
					// Duration
					if(!empty($data['duration'])) {
						$rightHtml .= '<p><i class="icon duration"></i>'.Text::label('job_duration').' : '.$data['duration'].'</p>';
					}	
					//Hive\Job\Contract\TimeSlot::className()
					// Job Caracteristics
					if(!empty($data['localization'])) {
						$rightHtml .= '<p><i class="icon localization"></i>'.Text::label('job_localization').' : '.$data['localization'].'</p>';
					}	
					// Required Skills Block
					if(!empty($data['skills'])) {
						$skills = $data['skills'];
						$skillsHtml = '<div class="announce-skills"><p><span class="skills-title">'.Msg(Hive::BUNDLE,Hive::ANNOUNCE_REQUIRED_SKILLS).'</span></p>';
						$skillsHtml .= '<p>'.Fox\Utilities\Text::toHtml($skills).'</p>';
						$skillsHtml .= '</div>';
					}
				?>
				<li class="threadRow  uiListItem uiListLight uiListVerticalItemBorder clear">
				<span class="announce-title"><?php echo $announce->title;?> <span class="announce-ref">(<?php echo $announce->reference;?>)</span> - 
					<?php echo $statusText;?>
				</span>
				<div class="pbm fsm fwn fcg">
					<?php echo $subTitle;?>
					<span class="UIActionLinks UIActionLinks_bottom">
						 &#8226; <a href="#" id="upd_<?php echo $aid;?>" class="<?php echo $behaviorUpdate->serialize(array(),'');?>"><?php echo Msg(Hive::BUNDLE,Hive::UPDATE); ?></a>
						 &#8226; <a href="#" id="del_<?php echo $aid;?>" class="<?php echo $behaviorDelete->serialize(array(),'');?>"><?php echo Msg(Hive::BUNDLE,Hive::DELETE); ?></a>
					</span>
				</div>
				<?php if(!empty($leftHtml) || !empty($rightHtml)) {?>
				<div class="announce-carac">
					<table class="announce-carac-table">
						<tr>
							<td style="width:50%">
							<div class="announce-carac-left">
							<?php echo $leftHtml;?>
							</div>
							</td>
							<td style="width:50%">
							<div class="announce-carac-right">
							<?php echo $rightHtml;?>
							</div>
						</td>
					</tr>
					</table>
				</div>
				<?php } ?>
				<div class="announce-content">
					<?php echo $skillsHtml;?>
					<div class="announce-description">
						<?php echo $announce->description; ?>
					</div>
				</div>
				</li>
				<?php 	
				} 
			}
			else
			{
			?>
			<li class="threadRow  uiListItem uiListLight uiListVerticalItemBorder ">
				<table class="uiGrid" cellspacing="0" cellpadding="0">
					<tbody><tr><td class="threadMainCol center">
				<span>
					<?php echo Msg(Hive::BUNDLE,Hive::MSG_NO_ANNOUNCES);?>
				</span>
				</td>
				</tr>
				</tbody>
				</table>
				
			</li>
		<?php 		
			}
		?>
		</ul>
	</div>
</div>